<?php

namespace App\Console\Commands;

use App\Models\Socket;
use Illuminate\Console\Command;

class ConnectSocket extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'socket:connect {open_id} {fd}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'socket 连接';

    protected $socket;

    /**
     * Create a new command instance.
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     * @throws \Exception
     */
    public function handle()
    {
        info($this->argument('fd'));
        info('open_id->'.$this->argument('open_id'));
        $fd = $this->argument('fd');
        $open_id = $this->argument('open_id');
        if ($fd && $open_id) {
            $socket = Socket::query()->firstOrNew(['open_id' => $open_id]);
            $socket->fd = $fd;
            $socket->save();
        }else{
            throw new \Exception('socket 参数错误');
        }
        return 'finish';
    }
}
